package com.company.project.core;

import com.alibaba.fastjson.JSON;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MsgMap  extends HashMap implements Map
{

	public static void main(String[] args) {
		MsgMap msg = new MsgMap();
		User user = new User();
		user.setName("xiaoming");
		user.setAge(22);
		msg.put("user" , user);
		System.out.println(msg);
		System.out.println(JSON.toJSONString(msg));
	}


	private Map map;
	private final static String MSG = "msg";
	private final static String CODE = "code";
	private final static String DATA = "data";
	private final static String URL = "url";

	public MsgMap()
	{
		map = new HashMap();
		this.putMsg("msg");
		this.putCode(0);
	}

	public MsgMap(int initialCapacity)
	{
		map = new HashMap(initialCapacity );
	}
	
	public MsgMap(int initialCapacity , float loadFactor)
	{
		map = new HashMap(initialCapacity , loadFactor);
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

	public void putMsg(String msg)
	{
		map.put(MSG , msg);
	}
	public String getMsg()
	{
		return (String) map.get(MSG);
	}
	public void putCode(int code)
	{
		map.put(CODE , code);
	}
	public void putCodeError()
	{
		map.put(CODE , MsgCode.ERROR);
	}
	public void putData(Object data)
	{
		map.put(DATA , data);
	}
	public void putUrl(Object data)
	{
		map.put(URL , data);
	}

	public Integer getCode()
	{
		Object obj = map.get(CODE);
		if(obj != null)
		{
			return (Integer) obj;
		}
		return Integer.MIN_VALUE;
	}

	@Override
	public Object get(Object key)
	{
		Object obj = null;
		obj = map.get(key);
		return obj;
	}
	private Map getMap()
	{
		return map;
	}
	public String getString(Object key)
	{
		return (String) get(key);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object put(Object key, Object value)
	{
		return map.put(key, value);
	}

	@Override
	public Object remove(Object key)
	{
		return map.remove(key);
	}

	public void clear()
	{
		map.clear();
	}

	public boolean containsKey(Object key)
	{
		return map.containsKey(key);
	}

	public boolean containsValue(Object value)
	{
		return map.containsValue(value);
	}

	public Set entrySet()
	{
		return map.entrySet();
	}

	public boolean isEmpty()
	{
		return map.isEmpty();
	}

	public Set keySet()
	{
		return map.keySet();
	}

	public void putAll(Map t)
	{
		map.putAll(t);
	}

	public int size()
	{
		return map.size();
	}

	public Collection values()
	{
		return map.values();
	}

	private static class User
	{
		private String name;
		private Integer age;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public Integer getAge() {
			return age;
		}

		public void setAge(Integer age) {
			this.age = age;
		}
	}
}
